package com.sh.service;

import com.sh.mapper.UserMapper;
import com.sh.pojo.User;
import com.sh.util.ResultUtil;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public ResultUtil login(String username, String password) {
        User login = userMapper.login(username, password);
        if (login != null){
            return ResultUtil.data(login);
        }else {
            return ResultUtil.err("用户名或密码错误");
        }
    }

    @Override
    public ResultUtil show(String username) {
        List<User> show = userMapper.show(username);
        return ResultUtil.data(show);
    }

    @Override
    public ResultUtil insert(String username, String truename, String password) {
        int i = userMapper.insert(username, truename, password);
        if (i > 0){
            return ResultUtil.ok("添加成功");
        }else {
            return ResultUtil.err("添加失败");
        }

    }

    @Override
    public ResultUtil update(Integer id, String username, String truename) {
        int i = userMapper.update(id, username, truename);
        if (i > 0){
            return ResultUtil.ok("修改成功");
        }else {
            return ResultUtil.err("修改失败");
        }
    }

    @Override
    public ResultUtil del(Integer id) {
        int i = userMapper.del(id);
        if (i > 0){
            return ResultUtil.ok("删除成功");
        }else {
            return ResultUtil.err("删除失败");
        }
    }
}
